<template>
  <div class="yl-container">
    <div class="yl-main">
      <!-- 搜索组 -->
      <div class="yl-search-list">
        <el-form :model="searchConfig" ref="searchConfig" :inline="true" label-position="top">
          <el-form-item>
            <el-input v-model="searchConfig.name" placeholder="请输入名字" type="text" size="small"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" round plain size="small" icon="el-icon-search">搜索</el-button>
          </el-form-item>
        </el-form>
      </div>
      <!-- 按钮组 -->
      <div class="yl-btn-group">
        <el-button type="primary" plain icon="el-icon-circle-plus-outline" @click="initData">新增</el-button>
        <el-button type="success" plain icon="el-icon-upload2" @click="uploadFile = true">导入</el-button>
        <el-button type="danger" plain icon="el-icon-delete">批量删除</el-button>
      </div>
      <!-- 表格 -->
      <div class="yl-table-list">
        <el-table
          v-loading="loading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.8)"
          stripe
          style="width: 100%"
          :data="tableData">

          <el-table-column  type="selection" width="60" align="center"></el-table-column>

          <el-table-column align="center" label="序号" show-overflow-tooltip width="60px">
            <template slot-scope="scope">
              <span>{{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>

          <el-table-column align="center"  label="姓名" show-overflow-tooltip prop="name"></el-table-column>

          <el-table-column align="center"  label="年龄" show-overflow-tooltip  prop="age"></el-table-column>

          <el-table-column align="center"  label="时间" show-overflow-tooltip prop="time"></el-table-column>

          <el-table-column align="right"  label="操作" width="300" fixed="right">
            <template>
              <el-button type="primary" plain size="mini" icon="el-icon-edit">编辑</el-button>
              <el-button type="success" plain size="mini" icon="el-icon-view">查看</el-button>
              <el-button type="danger" plain size="mini" icon="el-icon-delete">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="yl-page">
          <YlPage :page="page" :total="total" :size="pageSize"></YlPage>
        </div>
      </div>

      <!-- 新增修改弹出框 -->
      <el-dialog title="新增" class="yl-dialog" :visible.sync="dialogFormVisible">
        <el-form :model="form" ref="form" label-width="120px" :rules="rules" :inline="true" class="yl-form-item-inline__content">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="form.name" placeholder="请输入名字"></el-input>
          </el-form-item>
          <el-form-item label="下拉选项" prop="name">
            <el-select v-model="form.select" placeholder="选择对应数据">
              <el-option
                v-for="(item, index) in selects"
                :key="index"
                :value="item.value"
                :label="item.label"
              >
              </el-option>
            </el-select>
          </el-form-item>

          <!-- 地图 -->
          <el-form-item style="width: 100%; text-align: center">
            <yl-group></yl-group>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="addNewData" round>确 定</el-button>
          <el-button @click="dialogFormVisible = false" round>取 消</el-button>
        </div>
      </el-dialog>

      <!-- 导入 -->
      <el-dialog title="导入" class="yl-dialog" width="400px" :visible.sync="uploadFile">
        <el-form style="text-align: center">
          <el-form-item>
            <el-upload
              class="upload-demo"
              action="https://jsonplaceholder.typicode.com/posts/"
              multiple
              :limit="1">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
            </el-upload>
          </el-form-item>
        </el-form>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      // 转圈圈的圈圈
      loading: false,
      tableData: [
        {
          id: 1
        }
      ],
      page: 1,
      total: 100,
      pageSize: 10,
      // 搜索条件
      searchConfig: {
        name: ''
      },
      // 新增修改dialog
      dialogFormVisible: false,
      // 导入dialog
      uploadFile: false,
      // 新增修改表单
      form: {
        name: '',
        select: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入名字', trigger: 'blur' }
        ],
        select: [
          { required: true, message: '请选择数据', trigger: 'change' }
        ]
      },
      selects: [
        {
          value: 1,
          label: 1
        }
      ]
    }
  },
  methods: {
    initData () {
      this.dialogFormVisible = true
      // this.$ylapi.getAllDepart().then(res => console.log(res))
    },

    addNewData () {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
